package com.lyj.controller.es;

import com.lyj.domain.es.EsBlog;
import com.lyj.repository.es.EsBlogRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * blog 控制器
 *
 * Created by lyj on 2017/10/31.
 */
@RestController
@RequestMapping("/blogs")
public class BlogController {

    @Autowired
    private EsBlogRepository esBlogRepository;


    @GetMapping("/list")
    public List<EsBlog> list(@RequestParam(value = "title",required = false,defaultValue = "") String title,
                               @RequestParam(value = "summary",required = false,defaultValue = "") String summary,
                               @RequestParam(value = "content",required = false,defaultValue = "") String content,
                               @RequestParam(value = "pageIndex",defaultValue = "0") Integer pageIndex,
                               @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){

        //数据是在 Test 测试用例里的
        Pageable pageable=new PageRequest(pageIndex,pageSize);
        Page<EsBlog> page=esBlogRepository.findDistinctEsBlogByTitleContainingOrSummaryContainingOrContentContaining(title,summary,content,pageable);

        return page.getContent();
    }





}
